axios({
  method: "get",
  url: "http://cba.itlike.com/public/index.php?s=/api/page/detail&pageId=0",
}).then(({ data: res }) => {
  console.log(res.data.pageData);
  // 轮播图
  const banner = res.data.pageData.items[1].data;
  banner.forEach((ele) => {
    // console.log(imgUrl);
    document.querySelector(
      ".swiper-wrapper"
    ).innerHTML += `<div class="swiper-slide">
      <img src="${ele.imgUrl}" width="100%" alt="" />
  </div>`;
  });
  var mySwiper = new Swiper(".swiper", {
    speed: 300,
    loop: true,
    autoplay: 200,
    autoplay: {
      disableOnInteraction: false,
      delay: 800,
    },
    pagination: {
      el: ".swiper-pagination",
    },
    centeredSlides: true,
    observer: true, //修改swiper自己或子元素时，自动初始化swiper
    observeParents: true, //修改swiper的父元素时，自动初始化swiper
  });
  // 轮播图  结束

  // 分类
  const classify = res.data.pageData.items[3].data;
  classify.forEach(
    (item) =>
      (document.querySelector(
        ".classify"
      ).innerHTML += ` <a href="../智慧商城/classify.html">
      <img src="${item.imgUrl}" alt="">
      <p>${item.text}</p>
  </a>`)
  );
  // console.log(classify);

  // 主会场
  document.querySelector(
    ".home"
  ).innerHTML = ` <img src="${res.data.pageData.items[4].data[0].imgUrl}" alt="">`;
  // console.log(res.data.pageData.items[4].data[0].imgUrl);

  // 商品列表也
  const list = res.data.pageData.items[6].data;
  console.log(list);
  list.forEach((item) => {
    let str = "";
    if (item.line_price_max !== "0.00") {
      str += `<span>${"￥" + item.line_price_max}</span>`;
      // console.log(item.line_price_max);
    }
    document.querySelector(
      ".goods-item"
    ).innerHTML += ` <a href='../智慧商城/detailed.html'   class="item" data-id='${item.goods_id}'>
    <div class="left_photo" data-id='${item.goods_id}'>
        <img src="${item.goods_image}" alt="">
    </div>
    <div class="right_txt" data-id='${item.goods_id}'>
        <h3 data-id='${item.goods_id}'>${item.goods_name} </h3>
        <p data-id='${item.goods_id}'>已售${item.goods_sales}</p>
        <p data-id='${item.goods_id}'>￥${item.goods_price_max} <span>${str}</span></p>

    </div>
</a>`;
  });
  document.querySelector(".goods-item").addEventListener("click", function (e) {
    // console.log(item.goods_id);
    console.log(e.target.dataset.id);
    localStorage.setItem("data", e.target.dataset.id);
  });
});

//搜索
document.querySelector(".search").addEventListener("click", function () {});
